#include<iostream>
#include<pthread.h>
#include<cassert>
#include<unistd.h>
using namespace std;

int i = 0;
//新线程
void* thread_routine(void *args)//void * args = "thread one"
{
    // const char* name = (const char*)args;
    i = 5;
    while(true)
    {

        cout<<"我是一个新线程,i : i = 5 ,真实的i = " << i << endl;
        sleep(1);
    }

}

int main()
{
    pthread_t tid;
    int n = pthread_create(&tid , nullptr , thread_routine , (void*)"thread one");
    assert(0 == n);//成功的时候返回0
    (void)n;

    int y = 5;
    //主线程
    while(true)
    {
        cout<<"我是主线程，我的i = "<< i <<endl;
        y--;
        sleep(1);
        if(y == 0 )
        {
            i = 10;
            cout<<"主线程5s后将i = 10，真实的i = "<< i <<endl;
        }
    }
    return 0;
}
